package org.finesys.ai.config;

import org.finesys.chat.core.base.embedding.factory.EmbeddingProvider;
import org.finesys.chat.core.base.embedding.factory.EmbeddingStoreFactory;
import org.finesys.chat.core.base.embedding.factory.KnowledgeStoreFactory;
import org.finesys.chat.core.base.factory.ChatModelFactory;
import org.finesys.chat.core.base.service.ChatService;
import org.finesys.chat.core.base.service.LangEmbeddingService;
import org.finesys.chat.core.base.service.impl.ChatServiceImpl;
import org.finesys.chat.core.base.service.impl.LangEmbeddingServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class AigcConfig {


    @Bean
    @ConditionalOnMissingBean
    ChatModelFactory chatModelFactory() {
        return new ChatModelFactory();
    }

    @Bean
    @ConditionalOnMissingBean
    KnowledgeStoreFactory knowledgeStoreFactory() {
        return new KnowledgeStoreFactory();
    }

    @Bean
    @ConditionalOnMissingBean
    EmbeddingStoreFactory embeddingStoreFactory() {
        return new EmbeddingStoreFactory();
    }


    @Bean
    @ConditionalOnMissingBean
    @DependsOn({"chatModelFactory", "knowledgeStoreFactory", "embeddingStoreFactory"})
    public EmbeddingProvider embeddingProvider(EmbeddingStoreFactory embeddingStoreFactory,
                                               KnowledgeStoreFactory knowledgeStoreFactory,
                                               ChatModelFactory chatModelFactory) {
        return new EmbeddingProvider(embeddingStoreFactory, knowledgeStoreFactory, chatModelFactory);
    }

    @Bean
    @ConditionalOnMissingBean
    @DependsOn("chatModelFactory")
    ChatService chatService(ChatModelFactory chatModelFactory) {
        return new ChatServiceImpl(chatModelFactory);
    }

    @Bean
    @ConditionalOnMissingBean
    @DependsOn("embeddingProvider")
    LangEmbeddingService langEmbeddingService(EmbeddingProvider embeddingProvider) {
        return new LangEmbeddingServiceImpl(embeddingProvider);
    }
}
